
load('summary_data/figA15_A16.rda')

pal = c('blue',
        'deepskyblue',
        'darkslateblue',
        'chocolate1',
        'brown1',
        'darkred')

g1_out = out15[group == 'Non-College (College) White'] %>%
  ggplot(aes(nat_quant, color = class, group = class)) +
  geom_point(aes(y = f, shape = 'f'), position = position_dodge(width=.5), size = 2.5, alpha = 0.5)+
  geom_point(aes(y = m, shape = 'm'), position = position_dodge(width=.5), size = 1.5, alpha = 0.5) +
  geom_linerange(
    aes(ymin = f, ymax = m, xmin = nat_quant, xmax = nat_quant),
    position = position_dodge(width = 0.5),
    alpha = 0.5
    ) +
  theme_light() +
  theme(strip.background = element_rect(fill = 'white'), strip.text = element_text(color='black', size = 10)) +
  scale_y_continuous(labels=scales::label_percent(), limits = c(0,.55), breaks = seq(0,.55,.05)) +
  scale_shape_manual(name = element_blank(), values = c(20, 4), labels = c('Non-College White', 'College White')) +
  labs(x = element_blank(), y = '% Donor Retention', color = element_blank()) +
  scale_color_manual(values = pal[c(2:3, 5:6)]) +
  theme(
    legend.position = 'bottom',
    axis.text.x = element_text(angle = 0, vjust = 0.85, hjust = 0.5, size = 7),
    legend.margin = margin(0, 0, 0, 0),
    legend.spacing.x = unit(0, "mm"),
    legend.spacing.y = unit(0, "mm")
    ) +
  guides(color = guide_legend(nrow = 1, byrow = TRUE))

g2_out = out15[group == 'POC (White)'] %>%
  ggplot(aes(nat_quant, color = class, group = class)) +
  geom_point(aes(y = f, shape = 'f'), position = position_dodge(width=.5), size = 2.5,alpha = 0.5)+
  geom_point(aes(y = m, shape = 'm'), position = position_dodge(width=.5), size = 1.5,alpha = 0.5) +
  geom_linerange(
    aes(ymin = f, ymax = m, xmin = nat_quant, xmax = nat_quant),
    position = position_dodge(width = 0.5),
    alpha = 0.5
    ) +
  theme_light() +
  theme(strip.background = element_rect(fill = 'white'), strip.text = element_text(color='black', size = 10)) +
  scale_y_continuous(labels=scales::label_percent(), limits = c(0,.55), breaks = seq(0,.55,.05)) +
  scale_shape_manual(name = element_blank(), values = c(20, 4), labels = c('POC', 'White')) +
  labs(x = element_blank(), y = '% Donor Retention', color = element_blank()) +
  scale_color_manual(values = pal[c(2:3, 5:6)]) +
  theme(
    legend.position = 'bottom',
    axis.text.x = element_text(angle = 0, vjust = 0.85, hjust = 0.5, size = 7),
    legend.margin = margin(0, 0, 0, 0),
    legend.spacing.x = unit(0, "mm"),
    legend.spacing.y = unit(0, "mm")
    ) +
  guides(color = guide_legend(nrow = 2, byrow = TRUE))

g3_out = out15[group == 'Women (Men)'] %>%
  ggplot(aes(nat_quant, color = class, group = class)) +
  geom_point(aes(y = f, shape = 'f'), position = position_dodge(width = 0.5), size = 2.5, alpha = 0.5)+
  geom_point(aes(y = m, shape = 'm'), position = position_dodge(width = 0.5), size = 1.5, alpha = 0.5) +
  geom_linerange(
    aes(ymin = f, ymax = m, xmin = nat_quant, xmax = nat_quant),
    position = position_dodge(width = 0.5),
    alpha=0.5
    ) +
  theme_light() +
  theme(strip.background = element_rect(fill = 'white'), strip.text = element_text(color='black', size = 10)) +
  scale_y_continuous(labels=scales::label_percent(), limits = c(0,.55), breaks = seq(0,.55,.05)) +
  scale_shape_manual(name = element_blank(), values = c(20, 4), labels = c('Women', 'Men')) +
  labs(x = element_blank(), y = '% Donor Retention', color = element_blank()) +
  scale_color_manual(values = pal[c(2:3,5:6)]) +
  theme(
    legend.position = 'bottom',
    axis.text.x = element_text(angle = 0, vjust = .85, hjust=0.5, size = 7),
    legend.margin = margin(0, 0, 0, 0),
    legend.spacing.x = unit(0, "mm"),
    legend.spacing.y = unit(0, "mm")
    ) +
  guides(color = guide_legend(nrow = 2, byrow = TRUE))


plot = plot_grid(
  g1_out +
    guides(color='none', shape='none') +
    theme(legend.position='top') +
    theme(plot.margin = margin(t = -0.5,1,1,1)),
  g2_out +
    guides(color='none', shape='none') +
    theme(legend.position='top') +
    labs(y = element_blank()) +
    theme(plot.margin = margin(t = -0.5,1,1,1)),
  g3_out + 
    guides(color='none',shape='none') +
    theme(legend.position='top') +
    labs(y = element_blank()) +
    theme(plot.margin = margin(t = -0.5,1,1,1)),
  nrow = 1)

leg = plot_grid(
  get_legend_35(g1_out + guides(color='none')),
  get_legend_35(g2_out + guides(color='none')),
  get_legend_35(g3_out + guides(color='none')),
  nrow = 1)

plot = plot_grid(leg, plot, nrow = 2, rel_heights = c(1,9))

plot = plot_grid(plot, get_legend_35(g1_out + guides(shape='none')), nrow = 2, rel_heights = c(9,1))

grDevices::cairo_pdf('figures/figA15.pdf', width = 7, height = 4)
plot
dev.off()
